import request from '@/config/axios'

// AI 知识库分段 VO
export interface KnowledgeSegmentVO {
  id: number // 编号
  knowledgeId: number
  documentId: number // 文档编号
  content: string // 分段内容
  contentLength: number
  vectorId: string
  tokens: number
  retrievalCount: number
  status: number // 状态
}

export interface KnowledgeSegmentProcessVO {
  documentId: number
  count: number
  embeddingCount: number
}

// AI 知识库分段 API
export const KnowledgeSegmentApi = {
  // 获取AI 知识库分段分页
  getKnowledgeSegmentPage: async (params: PageParam) => {
    return await request.get({ url: `/ai/knowledge/segment/page`, params })
  },

  // 获取AI 知识库分段详情
  getKnowledgeSegment: async (id: number) => {
    return await request.get({ url: `/ai/knowledge/segment/get`, params: { id } })
  },

  // 新增AI 知识库分段
  createKnowledgeSegment: async (data: KnowledgeSegmentVO) => {
    return await request.post({ url: `/ai/knowledge/segment/create`, data })
  },

  // 修改AI 知识库分段
  updateKnowledgeSegment: async (data: KnowledgeSegmentVO) => {
    return await request.post({ url: `/ai/knowledge/segment/update`, data })
  },

  // 删除AI 知识库分段
  deleteKnowledgeSegment: async (id: number) => {
    return await request.delete({ url: `/ai/knowledge/segment/delete`, params: { id } })
  },

  // 切片内容
  splitContent: async (url: string, segmentMaxTokens: number) => {
    return await request.get({
      url: `/ai/knowledge/segment/split`,
      params: { url, segmentMaxTokens }
    })
  },

  // 获取AI 知识库分段处理列表
  getKnowledgeSegmentProcessList: async (documentIds: number[]) : Promise<KnowledgeSegmentProcessVO[]> => {
    return await request.get({
      url: `/ai/knowledge/segment/get-process-list`,
      params: { documentIds: documentIds.join(',') }
    })
  },

  // 修改AI 知识库分段状态
  updateKnowledgeSegmentStatus: async (id: number, status: number) => {
    return await request.post({ url: `/ai/knowledge/segment/update-status`, data: { id, status } })
  },

  // 搜索AI 知识库分段
  searchKnowledgeSegment: async (params: any) => {
    return await request.get({ url: `/ai/knowledge/segment/search`, params })
  }
}
